package com.zking;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntUnaryOperator;
import java.util.function.UnaryOperator;

class Dog{
    private String name="哮天犬";

    private int food=10;
    public static void bark(Dog dog){
        System.out.println(dog + "叫了");
    }

    @Override
    public String toString() {
        return super.toString();
    }

    /**
     * 吃狗粮
     * @param num
     * @return
     */
    public int eat(int num){
        System.out.println("吃了"+num+"晋狗粮");
        this.food-=num;
        return this.food;
    }
}
public class MethodRefrenceDemo {
    public static void main(String[] args) {
        //方法引用
        Dog dog=new Dog();
        dog.eat(1);
        Consumer<String> consumer=System.out::println;
        consumer.accept("接受的数据");

        //静态方法的方法引用
        Consumer<Dog> consumer1=Dog::bark;

        consumer1.accept(dog);

        //非静态方法 使用对象实例来引用
//        Function<Integer,Integer> function=dog::eat;
        IntUnaryOperator function=dog::eat;
        System.out.println("还剩下="+function.applyAsInt(2));


    }
}
